package _240314;

import java.util.*;

public class Main240314_2 {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int sum = 0;
		int N = scanner.nextInt();
		int[][] a = new int[N][3];
		for (int i=0; i<N; i++) {
			a[i][0] = scanner.nextInt();
			a[i][1] = scanner.nextInt();
			a[i][2] = 1; // 1表示为检测
		}
		for (int i = 0; i<N; i++) {
			for(int j=i+1; j<N; j++) {
				if (a[j][0] == a[i][0] && a[j][1]>a[i][1] && a[i][2] == 1) {
					sum = sum+a[i][1];
					a[i][2] = 0;
				}
			}
		}
		System.out.println(sum);
	}

}
